﻿using Ayatta.Contract.Domain;
using System.Collections.Generic;
using Ayatta.Common.Extensions;
using PagedList;

namespace Web.Seller.Models
{
    public static class ItemControllerModel
    {
        public class Index
        {
            public byte Param { get; set; }
            public string Keyword { get; set; }
            public string OuterId { get; set; }
            public int? CategoryRootId { get; set; }
            public decimal? PriceFrom { get; set; }
            public decimal? PriceTo { get; set; }
            public int? SaleFrom { get; set; }
            public int? SaleTo { get; set; }
            public IPagedList<ProductItem> Items { get; set; }
            public IDictionary<string, string> OrderByDic { get; set; }
            public static IList<string> OrderByKeys
            {
                get
                {
                    return new List<string> { "sale", "onlineTime" };
                }
            }

            public IDictionary<string, string> GetOrderByDic(string[] orderBy)
            {
                var dic = new Dictionary<string, string>();
                if (orderBy != null && orderBy.Length > 0)
                {
                    foreach (var o in orderBy)
                    {
                        var key = o.Split('.')[0];
                        if (key.IsIn(OrderByKeys))
                        {
                            var value = o.Split('.')[1];
                            dic[key] = value.ToLower() == "asc" ? "asc" : "desc";
                        }
                    }
                }
                return dic;
            }
        }
    }
}